﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace EasyTest.Logger {

    public class FileLogger : ILogger {

        public string OutputPath = Directory.GetCurrentDirectory();

        private StreamWriter sw;
        public void OpenLog() {

            string localFolder = string.Format("{0}\\log", OutputPath);

            if (!Directory.Exists(localFolder)) {
                Directory.CreateDirectory(localFolder);
            }

            string filename = string.Format("{0}\\filelogger.log", localFolder);

            sw = new StreamWriter(filename, true);
            sw.AutoFlush = true;
        }
        public void CloseLog() {
            if (sw != null) {
                sw.Close();
                sw.Dispose();
                sw = null;
            }
        }
        public void Log(string message) {
            if (sw != null)
                sw.WriteLine(message);
        }

        //public string GetTestMethodName() {
        //    try {
        //        // for when it runs via TeamCity
        //        return TestContext.CurrentContext.Test.Name;
        //    } catch {
        //        return "filelogger.log";
        //    }
        //}


    }

}
